package by.gravity.common.activity;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.LocalBroadcastManager;

public class CommonFragmentActivity extends FragmentActivity {
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		IntentFilter filter = new IntentFilter();
		addIntentFilter(filter);
		registerReceiver(filter);
	}

	protected void addIntentFilter(IntentFilter filter) {

	}

	@Override
	public void sendBroadcast(Intent intent) {
		LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
	}

	private void registerReceiver(IntentFilter filter) {
		if (filter.countActions() > 0) {
			BroadcastReceiver receiver = new BroadcastReceiver() {

				@Override
				public void onReceive(Context context, Intent intent) {
					onBroadcastReceive(intent);
				}
			};
			LocalBroadcastManager.getInstance(this).registerReceiver(receiver, filter);
		}
	}

	protected void onBroadcastReceive(Intent intent) {

	}
}
